Chart for WinRT
Data Binding in Code

The steps required to create data bound charts are as follows:

  1. Choose the chart type (ChartType property).
  2. Set up the axes (AxisX and AxisY properties).
  3. Set the ItemsSource property to the collection of items that contain the desired chart data.
  4. Use the dataSeries.ValueBinding property to specify which item property contains the values to be plotted.
  5. Adjust the chart's appearance using the Palette property.

The steps listed above are similar to the steps you've used to create other C1Charts, except for Steps 3 and 4.

To illustrate the difference, take a look at the code used to create a chart without bound data:

C# Unbound
Copy Code
// Get the data
var data = GetSalesPerRegionData();
// Show regions along label axis
_c1Chart.Data.ItemNames = (
from r in data
select r.Region).ToArray();
// Add Revenue series
var ds = new DataSeries();
ds.Label = "Revenue";
ds.ValuesSource = (from r in data select r.Revenue).ToArray();
_c1Chart.Data.Children.Add(ds);
// Add Expense series
ds = new DataSeries();
ds.Label = "Expense";
ds.ValuesSource = (from r in data select r.Expense).ToArray();
_c1Chart.Data.Children.Add(ds);
// Add Profit series
ds = new DataSeries();
ds.Label = "Profit";
ds.ValuesSource = (from r in data select r.Profit).ToArray();
_c1Chart.Data.Children.Add(ds);

Here is the data-bound version of the code. The result is identical:

C# Bound
Copy Code
// Get the data
            var data = GetSalesPerRegionData();
            chart.Data.ItemsSource = data;
            //Show regions along label axis
            chart.Data.ItemNameBinding = newBinding() { Path = newPropertyPath("Region")  };
            // Add data series
            foreach(stringseries in"Revenue,Expense,Profit".Split(','))
            {
                vards = newDataSeries();
                ds.Label = series;
                ds.ValueBinding = newBinding() { Path = newPropertyPath(series) };
                chart.Data.Children.Add(ds);
            }

The data-bound version of the code is even more compact than the original. The three series are created in a loop, taking advantage of the fact that the names of the properties we want to chart are the same as the names we want to use for each data series.

 

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback